//
//  FavorManager.m
//  RoadKnowEntertainment
//
//  Created by lanou on 16/8/9.
//  Copyright © 2016年 RKE. All rights reserved.
//

#import "FavorManager.h"
static FavorManager *_manager = nil;
@implementation FavorManager

+ (instancetype)shareFavor {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _manager = [[FavorManager alloc] init];
    });
    return _manager;
}

- (void)insertObject:(NSString *)object forKey:(NSString *)key className:(NSString *)className{
    
    self.todo = [AVObject objectWithClassName:className];
    [self.todo setObject:object forKey:key];
    [self.todo saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            // 存储成功
            NSLog(@"存储成功");
        } else {
            // 失败的话，请检查网络环境以及 SDK 配置是否正确
            NSLog(@"存储失败");
        }
    }];
}

- (void)updateObject:(NSString *)className objectID:(NSString *)objectID object:(NSString *)object key:(NSString *)key {
    self.todo = [AVObject objectWithClassName:className objectId:objectID];
    [self.todo setObject:object forKey:key];
    [self.todo saveInBackground];
}

- (void)syncObject:(NSString *)object className:(NSString *)className objectID:(NSString *)objectID {
    
    self.todo = [AVObject objectWithClassName:className objectId:objectID];
    [self.todo fetchIfNeededInBackgroundWithBlock:^(AVObject *object, NSError *error) {
        
    }];
}

@end
